<div id="bd">
<br/>
<form action="/replay" method="post" id="replay_form" target="_blank" class="form_0" autocomplete="off">
<div class="h4">replay</div>
<fieldset>
<legend>basic</legend>
<table>
<tr><th>action url:</th><td><input type="text" name="basic_action_url" value="{{.action_url}}" class="form-control"></td></tr>
<tr><th>method:</th><td><input type="text" name="basic_method" value="{{.req.method}}" class="form-control" ></td></tr>
<tr><th>Host:</th><td><input type="text" name="basic_host" value="{{.req.host}}" class="form-control"></td></tr>
</table>
<input type="hidden" name="basic_RemoteAddr" value="{{.req.client_ip}}">
<input type="hidden" name="basic_user" value="{{.req.user}}">
</fieldset>

<fieldset>
<legend>header 
<font color=gray>(only use these replay with pproxy)</font> &nbsp;
<a href="#" onclick="$('#tb_header').toggle()">show/hide</a>
</legend>
<table id="tb_header" style="display:none">
{{range $k,$v:=.req.header}}
<tr>
<th>{{$k}}:</th>
<td>
  {{range $index,$_v:=$v}}
    <div><input type="text" name="header_{{$k}}" value="{{$_v|html}}" class="form-control"></div>
 {{end}}
 </td>
 <td class="last">
 <div>
<a href="#" onclick="return add_tr(this,'header_')">+</a>&nbsp;
<a href="#" onclick="return toggle_able_tr(this)" title="toggle disable">X</a>
</div>
</td>
 </tr>
{{end}}
</table>
</fieldset>

<fieldset>
<legend>get_params
<a href="#" onclick="return add_tr('#tb_form_get','get_')">+param</a>
</legend>
<table id="tb_form_get">
{{range $k,$v:=.req.form_get}}
<tr><th>{{$k}}:</th> <td>
{{range $index,$_v:=$v}}
<div><input type="text" name="get_{{$k}}" value="{{$_v|html}}" class="form-control"></div>
{{end}}
</td>

<td class="last">
<div>
<a href="#" onclick="return add_tr(this,'get_')">+</a>&nbsp;
<a href="#" onclick="return toggle_able_tr(this)" title="toggle disable">X</a>
</div>
</td>

</tr>
{{end}}

</table>
</fieldset>

{{if eq .req.method  "POST"}}
<fieldset>
<legend>post_params
<a href="#" onclick="return add_tr('#tb_form_post','post_')">+param</a>
</legend>
<table id="tb_form_post">
{{range $k,$v:=.req.form_post}}
<tr><th>{{$k}}:</th><td> 
{{range $index,$_v:=$v}}
<div><input type="text" name="post_{{$k}}" value="{{$_v|html}}" class="form-control"></div>
{{end}}
</td>
<td class="last">
<div>
<a href="#" onclick="return add_tr(this,'post_')">+</a>&nbsp;
<a href="#" onclick="return toggle_able_tr(this)" title="toggle disable">X</a>
</div>
</td>
</tr>
{{end}}
</table>
</fieldset>
{{end}}
<br/>
<div style="text-align:center;">
<input type="hidden" name="replay" id="replay" value="pproxy">
<input type="submit"  class="btn btn-primary"  value="replay with pproxy" onclick="$('#replay').val('pproxy')">
<span style="margin-left:100px"></span>
<input type="submit"  class="btn btn-primary" value="replay direct" onclick="$('#replay').val('direct')">
</div>
</form>
<br/>
<br/>

</div>

<script>
function toggle_able_tr(obj){
	$(obj).parents("tr").find("input").each(function(){
		if($(this).attr("disabled")){
		   $(this).removeAttr("disabled");
		}else{
		   $(this).attr("disabled","disabled");
		}
	});
	return false;
}

function add_tr(obj,pre){
   var html="<tr>\
   <th><input type='text' class='form-control' style='text-align:right;width:80%' onkeyup='tr_val_chnage(this,\""+pre+"\")' placeholder='param name'>:</th>\
   <td><input type='text' disabled=disabled class='form-control' placeholder='param value'></td>\
   <td class='last'><a href='#' onclick='$(this).parents(\"tr\").remove();return flase;'>del</a></td>\
   </tr>";
   if(typeof obj=="object"){
    $(obj).parents("tr").after(html);
   }else{
	   $(obj).prepend(html)
   }
   return false;
}

function tr_val_chnage(obj,pre){
	var next_input=$(obj).parents("tr").find("td input");
	var val=$.trim($(obj).val());
	if(val==""){
		next_input.attr("disabled","disabled");
	}else{
		next_input.attr("name",pre+val).removeAttr("disabled");
	}
}
</script>
